<template>
  <van-popup v-model="status" position="bottom" :close-on-click-overlay="false">
    <van-picker show-toolbar :columns="datasource" @cancel="onCancel" @confirm="onConfirm" />
  </van-popup>
</template>

<script>
import { converFormatText } from '@/utils/index'
export default {
  name: 'Picker',
  props: {
    status: {
      type: Boolean,
      default: false
    },
    columns: {
      type: Array,
      required: true
    },
    title: {
      type: String,
      required: false
    }
  },
  data() {
    return {
      isShow: this.status
    }
  },
  computed: {
    datasource() {
      return converFormatText(this.columns)
    }
  },
  methods: {
    onConfirm(value, index) {
      this.isShow = false
      const params = {
        status: this.isShow,
        value,
        title: this.title
      }
      this.$emit('sendToParent', params)
    },
    onCancel() {
      const params = {
        status: false,
        title: this.title
      }
      this.$emit('sendToParent', params)
    }
  }
}
</script>

<style scoped lang="less">
</style>